//// Copyright 2008 David Mitchell
//// Released under the MIT License

//using System;
//using System.Collections.Generic;
//using System.Runtime.InteropServices;

//namespace NSDuctTape
//{
//  internal class ObjectiveCMethodList
//  {
//    public ObjectiveCMethodList(IList<ObjectiveCMethod> methods)
//    {
//      if (methods == null)
//        throw new ArgumentNullException("methods");
//      if (methods.Count == 0)
//        throw new ArgumentException("methods must contain at least one method.", "methods");
			
//      _methods = new List<ObjectiveCMethod>(methods);
//    }

//    public IntPtr ToIntPtr()
//    {
//      if (_nativeList == IntPtr.Zero)
//      {
//        IntPtr nativeList = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(MethodList)) + (Marshal.SizeOf(typeof(ObjectiveCMethodInfo)) * _methods.Count));
//        MethodList list = new MethodList();
//        list.methodCount = _methods.Count;
//        Marshal.StructureToPtr(list, nativeList, false);

//        IntPtr current = (IntPtr)((int)nativeList + Marshal.SizeOf(list));
//        foreach (ObjectiveCMethod method in _methods)
//        {
//          ObjectiveCMethodInfo methodInfo = new ObjectiveCMethodInfo();
//          methodInfo.name = ObjectiveCMethods.SelectorFromString(method.Name);
//          methodInfo.types = Marshal.StringToHGlobalAnsi(method.Types);
//          methodInfo.implementation = method.Implementation;
//          Marshal.StructureToPtr(methodInfo, current, false);
//          current = (IntPtr)((int)current + Marshal.SizeOf(methodInfo));
//        }
//        _nativeList = nativeList;
//      }

//      return _nativeList;
//    }

//    IntPtr _nativeList;
//    List<ObjectiveCMethod> _methods;

//    [StructLayout(LayoutKind.Sequential)]
//    private struct MethodList
//    {
//      public IntPtr obsolete;
//      public int methodCount;
//    }
//  }
//}
